package com.tomvian.twodee.common 
{
	import com.tomvian.twodee.common.interactions.Interaction;
	/**
	 * InteractionManager
	 * @author Thomas Vian
	 */
	public class InteractionManager
	{
		//--------------------------------------------------------------------------
		//
		//  Properties
		//
		//--------------------------------------------------------------------------
		
		public static const instance:InteractionManager = new InteractionManager;
		
		protected var _interactions:Interaction;
		
		//--------------------------------------------------------------------------
		//
		//  Getters / Setters
		//
		//--------------------------------------------------------------------------
		
		//--------------------------------------------------------------------------
		//
		//  Constructor
		//
		//--------------------------------------------------------------------------
		
		public function InteractionManager() 
		{
			
		}
		
		//--------------------------------------------------------------------------
		//
		//  Methods
		//
		//--------------------------------------------------------------------------
		
		public function clearInteractions():void
		{
			_interactions = null;
		}
		
		public function addInteractions(...rest:Array):void
		{
			for (var i:uint = 0, l:uint = rest.length; i < l; i++)
			{
				var interaction:Interaction = rest[i];
				
				if (!_interactions) 
				{
					_interactions = interaction;
				}
				else
				{
					interaction.next = _interactions;
					_interactions.last = interaction;
					_interactions = interaction;
				}
			}
		}
		
		public function act():void
		{
			var interactionList:Interaction = _interactions;
			while (interactionList)
			{
				interactionList.interact();
				interactionList = interactionList.next;
			}
		}
	}
}